package com.ufo.store.management.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;

import com.ufo.store.management.utils.Utils;

import java.util.Locale;

public class LocalDatabaseHelper extends SQLiteOpenHelper {
    private SQLiteDatabase mDataBase = null;
    private Context mContext = null;
    private static LocalDatabaseHelper sInstance = null;

    // 数据库名称
    private static String DB_NAME = "store_local";
    // 数据库版本
    private static int DB_VERSION = 1;

    public static synchronized LocalDatabaseHelper getInstance(Context context) {
        if (sInstance == null)
            sInstance = new LocalDatabaseHelper(context);
        return sInstance;
    }

    public LocalDatabaseHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
        this.mContext = context;
        // 只有调用了DatabaseHelper的getWritableDatabase()方法或者getReadableDatabase()方法之后，才会创建或打开一个连接
        //SQLiteDatabase sqliteDatabase = LocalDatabaseHelper.getReadableDatabase();
        mDataBase = getWritableDatabase();
    }

    /**
     * 当第一次创建数据库的时候，调用该方法
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        // 创建fastfood商品类目表
        db.execSQL("create table " + DatabaseManager.STOCK_TYPE_TABLE_NAME
                + " (" + DatabaseManager.LOCAL_STOCK_TYPE_TABLE_NAME_PRIMARY + " integer primary key,"
                + DatabaseManager.STOCK_TYPE_TYPEID + " char(7),"
                + DatabaseManager.STOCK_TYPE_TYPENAME + " varchar(21)"
                + ")");
        // 创建fastfood商品表
        db.execSQL("create table " + DatabaseManager.STOCK_TABLE_NAME
                + " (" + DatabaseManager.LOCAL_STOCK_STOCKID_PRIMARY + " integer primary key,"
                + DatabaseManager.STOCK_STOCKID + " char(7),"
                + DatabaseManager.STOCK_STOCKNAME + " varchar(30),"
                + DatabaseManager.STOCK_SPELL + " varchar(15),"
                + DatabaseManager.STOCK_TYPEID + " char(7),"
                + DatabaseManager.STOCK_COST + " decimal(10, 2),"
                + DatabaseManager.STOCK_RETAIL_PRICE + " decimal(10, 2),"
                + DatabaseManager.STOCK_MEMBER_PRICE + " decimal(10, 2),"
                + DatabaseManager.STOCK_BARCODE + " varchar(15)"
                + ")");
        // 创建fastfood会员表
        db.execSQL("create table " + DatabaseManager.MEMBER_TABLE_NAME
                + " (" + DatabaseManager.LOCAL_MEMBER_MEMBERID_PRIMARY + " integer primary key,"
                + DatabaseManager.MEMBER_MEMBERID + " char(20),"
                + DatabaseManager.MEMBER_NAME + " varchar(10),"
                + DatabaseManager.MEMBER_NAME_SPELL + " varchar(30),"
                + DatabaseManager.MEMBER_SEX + " char(2),"
                + DatabaseManager.MEMBER_MOBILE + " varchar(15),"
                + DatabaseManager.MEMBER_POINT + " decimal(10, 2),"
                + DatabaseManager.MEMBER_MEMBERTYPE + " varchar(20),"
                + DatabaseManager.MEMBER_CARDID + " char(20),"
                + DatabaseManager.MEMBER_MODIFY_SN + " int,"
                + DatabaseManager.MEMBER_TOTAL_CONSUME + " decimal(10, 2)"
                + ")");
        // 创建fastfood销售额表
        db.execSQL("create table " + DatabaseManager.PAY_MASTER_TABLE_NAME
                + " (" + DatabaseManager.LOCAL_PAY_MASTER_PRIMARY + " integer primary key,"
                + DatabaseManager.PAY_MASTER_BILLNO + " char(23),"
                + DatabaseManager.PAY_MASTER_OPERDATE + " datetime,"
                + DatabaseManager.PAY_MASTER_BLOTOUT + " decimal(10, 2),"
                + DatabaseManager.PAY_MASTER_TOTAL + " decimal(10, 2),"
                + DatabaseManager.PAY_MASTER_RECEIVABLE + " decimal(10, 2)"
                + ")");
        //创建fastfood销售详情表
        db.execSQL("create table " + DatabaseManager.SALE_DETAIL_TABLE_NAME
                + " (" + DatabaseManager.LOCAL_SALE_DETAIL_PRIMARY + " integer primary key,"
                + DatabaseManager.SALE_DETAIL_BILLNO + " char(23),"
                + DatabaseManager.SALE_DETAIL_STOCKID + " char(7),"
                + DatabaseManager.SALE_DETAIL_QUANTITY + " decimal(10, 2),"
                + DatabaseManager.SALE_DETAIL_OPERATEDATE + " datetime,"
                + DatabaseManager.SALE_DETAIL_PRICE + " decimal(10, 2),"
                + DatabaseManager.SALE_DETAIL_COST + " decimal(10, 2),"
                + DatabaseManager.SALE_DETAIL_PRICE_ORIG + " decimal(10, 2)"
                + ")");

        // 创建isszmbalv3商品类目表
        db.execSQL("create table " + DatabaseManager.ISSZMBALV3_ITEM_CLS_TABLE_NAME
                + " (" + DatabaseManager.LOCAL_ISSZMBALV3_ITEM_CLS_TABLE_NAME_PRIMARY + " integer primary key,"
                + DatabaseManager.ISSZMBALV3_ITEM_CLS_ITEM_CLSNO + " char(20),"
                + DatabaseManager.ISSZMBALV3_ITEM_CLS_ITEM_CLSNAME + " varchar(20)"
                + ")");
        // 创建isszmbalv3商品表
        db.execSQL("create table " + DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME
                + " (" + DatabaseManager.LOCAL_ISSZMBALV3_t_bd_item_info_TABLE_NAME_PRIMARY + " integer primary key,"
                + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + " char(20),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name + " varchar(40),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_subname + " varchar(20),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno + " char(20),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_item_rem + " varchar(10),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_price + " numeric(16, 4),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_sale_price + " numeric(16, 4),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_measure_flag + " char(1),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_new_oper_id + " char(4),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_modify_oper_id + " char(4),"
                + DatabaseManager.ISSZMBALV3_t_bd_item_vip_acc_flag + " char(1)"
                + ")");
        // 创建isszmbalv3会员表
        db.execSQL("create table " + DatabaseManager.ISSZMBALV3_t_rm_vip_info_TABLE_NAME
                + " (" + DatabaseManager.LOCAL_ISSZMBALV3_t_rm_vip_info_TABLE_NAME_PRIMARY + " integer primary key,"
                + DatabaseManager.ISSZMBALV3_t_rm_vip_card_type + " char(2),"
                + DatabaseManager.ISSZMBALV3_t_rm_vip_card_id + " varchar(20),"
                + DatabaseManager.ISSZMBALV3_t_rm_vip_card_no + " varchar(20),"
                + DatabaseManager.ISSZMBALV3_t_rm_vip_vip_name + " varchar(8),"
                + DatabaseManager.MEMBER_NAME_SPELL + " varchar(30),"
                + DatabaseManager.ISSZMBALV3_t_rm_vip_vip_sex + " char(2),"
                + DatabaseManager.ISSZMBALV3_t_rm_vip_vip_tel + " varchar(20),"
                + DatabaseManager.ISSZMBALV3_t_rm_vip_vip_email + " varchar(30),"
                + DatabaseManager.ISSZMBALV3_t_rm_vip_mobile + " varchar(20),"
                + DatabaseManager.ISSZMBALV3_t_rm_vip_consum_count + " int,"            //消费次数
                + DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt + " numeric(16, 4),"   //消费总额
                + DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num + " numeric(10, 2),"      //累计积分
                + DatabaseManager.ISSZMBALV3_t_rm_vip_dec_num + " numeric(10, 2),"      //已用积分
                + DatabaseManager.ISSZMBALV3_t_rm_vip_vip_start_date + " datetime,"     //vip开始时间
                + DatabaseManager.ISSZMBALV3_t_rm_vip_vip_end_date + " datetime,"       //vip结束时间
                + DatabaseManager.ISSZMBALV3_t_rm_vip_sav_start_date + " datetime,"     //储蓄开始时间
                + DatabaseManager.ISSZMBALV3_t_rm_vip_sav_end_date + " datetime"        //储蓄结束时间
                + ")");
        // 创建isszmbalv3门店列表
        db.execSQL("create table " + DatabaseManager.ISSZMBALV3_BRANCH_INFO_TABLE_NAME
                + " (" + DatabaseManager.ISSZMBALV3_BRANCH_INFO_TABLE_NAME_PRIMARY + " integer primary key,"
                + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + " char(6),"
                + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NAME + " char(30),"
                + DatabaseManager.ISSZMBALV3_BRANCH_INFO_PROPERTY+ " char(1)"
                + ")");
        // 创建isszmbalv3供应商列表
        db.execSQL("create table " + DatabaseManager.ISSZMBALV3_t_bd_supcust_info_TABLE_NAME
                + " (" + DatabaseManager.ISSZMBALV3_t_bd_supcust_info_TABLE_NAME_PRIMARY + " integer primary key,"
                + DatabaseManager.ISSZMBALV3_t_bd_supcust_info_supcust_no + " char(8),"
                + DatabaseManager.ISSZMBALV3_t_bd_supcust_info_sup_name + " varchar(60),"
                + DatabaseManager.ISSZMBALV3_t_bd_supcust_info_sup_type+ " char(4)"
                + ")");
        // 创建isszmbalv3销售额表
        db.execSQL("create table " + DatabaseManager.ISSZMBALV3_PAY_FLOW_TABLE_NAME
                + " (" + DatabaseManager.ISSZMBALV3_PAY_FLOW_TABLE_NAME_PRIMARY + " integer primary key,"
                + DatabaseManager.ISSZMBALV3_PAY_FLOW_FLOW_NO + " char(18),"
                + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + " char(6),"
                + DatabaseManager.ISSZMBALV3_PAY_FLOW_OPERDATE + " datetime,"
                + DatabaseManager.ISSZMBALV3_PAY_FLOW_SALE_AMOUNT + " decimal(16, 4),"
                + DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_AMOUNT + " decimal(16, 4),"
                + DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_WAY+ " char(3)"
                + ")");
        //创建isszmbalv3销售详情表
        db.execSQL("create table " + DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME
                + " (" + DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME_PRIMARY + " integer primary key,"
                + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + " char(18),"
                + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + " char(6),"
                + DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + " datetime,"
                + DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + " char(20),"
                + DatabaseManager.ISSZMBALV3_SALE_FLOW_SOURCE_PRICE + " numeric(16, 4),"
                + DatabaseManager.ISSZMBALV3_SALE_FLOW_COST_PRICE + " numeric(16, 4),"
                + DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_QNTY + " numeric(16, 4),"
                + DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_MONER + " numeric(16, 4)"
                + ")");
    }

    /**
     * 当更新数据库的时候执行该方法
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //输出更新数据库的日志信息

    }

    /**
     * 关闭数据库
     *
     * @return 无
     */
    public void close() {
        mDataBase.close();
    }

    /**
     * 添加商品
     */
    public int insertStock(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.STOCK_TABLE_NAME
                            + "(" + DatabaseManager.STOCK_STOCKID + ","
                            + DatabaseManager.STOCK_STOCKNAME + ","
                            + DatabaseManager.STOCK_SPELL + ","
                            + DatabaseManager.STOCK_TYPEID + ","
                            + DatabaseManager.STOCK_COST + ","
                            + DatabaseManager.STOCK_RETAIL_PRICE + ","
                            + DatabaseManager.STOCK_MEMBER_PRICE + ","
                            + DatabaseManager.STOCK_BARCODE + ") VALUES (?,?,?,?,?,?,?,?)",
                    new Object[]{values.get(DatabaseManager.STOCK_STOCKID),
                            values.get(DatabaseManager.STOCK_STOCKNAME),
                            values.get(DatabaseManager.STOCK_SPELL),
                            values.get(DatabaseManager.STOCK_TYPEID),
                            values.get(DatabaseManager.STOCK_COST),
                            values.get(DatabaseManager.STOCK_RETAIL_PRICE),
                            values.get(DatabaseManager.STOCK_MEMBER_PRICE),
                            values.get(DatabaseManager.STOCK_BARCODE)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getById(String rowId, int startIndex, int pageSize, int sortMode) {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.STOCK_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }

            String sql = "SELECT " + DatabaseManager.STOCK_STOCKID + "," +
                    DatabaseManager.STOCK_STOCKNAME + "," +
                    DatabaseManager.STOCK_TYPEID + "," +
                    DatabaseManager.STOCK_COST + "," +
                    DatabaseManager.STOCK_RETAIL_PRICE + "," +
                    DatabaseManager.STOCK_MEMBER_PRICE + "," +
                    DatabaseManager.STOCK_BARCODE + "," +
                    DatabaseManager.STOCK_SPELL +
                    " FROM " + DatabaseManager.STOCK_TABLE_NAME + " WHERE  " + DatabaseManager.STOCK_STOCKID + "  like '%" + rowId + "%'" + " ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;//查询表名为“stock”的所有内容
            cursor = mDataBase.rawQuery(sql, null);
//			cursor = mDataBase.query(true, DatabaseManager.STOCK_TABLE_NAME, new String[]{
//					DatabaseManager.STOCK_STOCKID,
//					DatabaseManager.STOCK_STOCKNAME,
//					DatabaseManager.STOCK_SPELL,
//					DatabaseManager.STOCK_TYPEID,
//					DatabaseManager.STOCK_COST,
//					DatabaseManager.STOCK_RETAIL_PRICE,
//					DatabaseManager.STOCK_MEMBER_PRICE,
//					DatabaseManager.STOCK_BARCODE
//			}, DatabaseManager.STOCK_STOCKID + "  like '%" + rowId + "%'", null, null,
//					null, null, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getById1(String rowId) {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sql = "SELECT " + DatabaseManager.STOCK_STOCKID + "," +
                    DatabaseManager.STOCK_STOCKNAME + "," +
                    DatabaseManager.STOCK_TYPEID + "," +
                    DatabaseManager.STOCK_COST + "," +
                    DatabaseManager.STOCK_RETAIL_PRICE + "," +
                    DatabaseManager.STOCK_MEMBER_PRICE + "," +
                    DatabaseManager.STOCK_BARCODE + "," +
                    DatabaseManager.STOCK_SPELL +
                    " FROM " + DatabaseManager.STOCK_TABLE_NAME + " WHERE  " + DatabaseManager.STOCK_STOCKID + "  = " + rowId ;//查询表名为“stock”的所有内容
            cursor = mDataBase.rawQuery(sql, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getByName(String name, int startIndex, int pageSize, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.STOCK_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }

            String sql = "SELECT " + DatabaseManager.STOCK_STOCKID + "," +
                    DatabaseManager.STOCK_STOCKNAME + "," +
                    DatabaseManager.STOCK_TYPEID + "," +
                    DatabaseManager.STOCK_COST + "," +
                    DatabaseManager.STOCK_RETAIL_PRICE + "," +
                    DatabaseManager.STOCK_MEMBER_PRICE + "," +
                    DatabaseManager.STOCK_BARCODE + "," +
                    DatabaseManager.STOCK_SPELL +
                    " FROM " + DatabaseManager.STOCK_TABLE_NAME + " WHERE  " + DatabaseManager.STOCK_STOCKNAME + "  like '%" + name + "%'" + " ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;//查询表名为“stock”的所有内容
            cursor = mDataBase.rawQuery(sql, null);
//			cursor = mDataBase.query(DatabaseManager.STOCK_TABLE_NAME, new String[]{
//							DatabaseManager.STOCK_STOCKID,
//							DatabaseManager.STOCK_STOCKNAME,
//							DatabaseManager.STOCK_SPELL,
//							DatabaseManager.STOCK_TYPEID,
//							DatabaseManager.STOCK_COST,
//							DatabaseManager.STOCK_RETAIL_PRICE,
//							DatabaseManager.STOCK_MEMBER_PRICE,
//							DatabaseManager.STOCK_BARCODE
//			}, DatabaseManager.STOCK_STOCKNAME + "  like '%" + name + "%'", null,
//					null, null, null, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getByBarcode(String barcode, int startIndex, int pageSize, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.STOCK_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }

            String sql = "SELECT " + DatabaseManager.STOCK_STOCKID + "," +
                    DatabaseManager.STOCK_STOCKNAME + "," +
                    DatabaseManager.STOCK_TYPEID + "," +
                    DatabaseManager.STOCK_COST + "," +
                    DatabaseManager.STOCK_RETAIL_PRICE + "," +
                    DatabaseManager.STOCK_MEMBER_PRICE + "," +
                    DatabaseManager.STOCK_BARCODE + "," +
                    DatabaseManager.STOCK_SPELL +
                    " FROM " + DatabaseManager.STOCK_TABLE_NAME + " WHERE  " + DatabaseManager.STOCK_BARCODE + "  like '%" + barcode + "%'" + " ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;//查询表名为“stock”的所有内容
            cursor = mDataBase.rawQuery(sql, null);
//			cursor = mDataBase.query( DatabaseManager.STOCK_TABLE_NAME, new String[]{
//							DatabaseManager.STOCK_STOCKID,
//							DatabaseManager.STOCK_STOCKNAME,
//							DatabaseManager.STOCK_SPELL,
//							DatabaseManager.STOCK_TYPEID,
//							DatabaseManager.STOCK_COST,
//							DatabaseManager.STOCK_RETAIL_PRICE,
//							DatabaseManager.STOCK_MEMBER_PRICE,
//							DatabaseManager.STOCK_BARCODE
//			},  DatabaseManager.STOCK_BARCODE+"  like '%" +barcode + "%'",null,
//					null, null, null, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getBySpell(String spell, int startIndex, int pageSize, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.STOCK_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }

            String sql = "SELECT " + DatabaseManager.STOCK_STOCKID + "," +
                    DatabaseManager.STOCK_STOCKNAME + "," +
                    DatabaseManager.STOCK_TYPEID + "," +
                    DatabaseManager.STOCK_COST + "," +
                    DatabaseManager.STOCK_RETAIL_PRICE + "," +
                    DatabaseManager.STOCK_MEMBER_PRICE + "," +
                    DatabaseManager.STOCK_BARCODE + "," +
                    DatabaseManager.STOCK_SPELL +
                    " FROM " + DatabaseManager.STOCK_TABLE_NAME + " WHERE  " + DatabaseManager.STOCK_SPELL + "  like '%" + spell + "%'" + " ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;//查询表名为“stock”的所有内容
            cursor = mDataBase.rawQuery(sql, null);
//			cursor = mDataBase.query( DatabaseManager.STOCK_TABLE_NAME, new String[]{
//							DatabaseManager.STOCK_STOCKID,
//							DatabaseManager.STOCK_STOCKNAME,
//							DatabaseManager.STOCK_SPELL,
//							DatabaseManager.STOCK_TYPEID,
//							DatabaseManager.STOCK_COST,
//							DatabaseManager.STOCK_RETAIL_PRICE,
//							DatabaseManager.STOCK_MEMBER_PRICE,
//							DatabaseManager.STOCK_BARCODE
//			},  DatabaseManager.STOCK_SPELL+"  like '%" +spell + "%'",null,
//					null, null, null, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getByTypeId(String typeId, int startIndex, int pageSize, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.STOCK_STOCKID;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.STOCK_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.STOCK_STOCKID ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }

            String sql = "SELECT " + DatabaseManager.STOCK_STOCKID + "," +
                    DatabaseManager.STOCK_STOCKNAME + "," +
                    DatabaseManager.STOCK_TYPEID + "," +
                    DatabaseManager.STOCK_COST + "," +
                    DatabaseManager.STOCK_RETAIL_PRICE + "," +
                    DatabaseManager.STOCK_MEMBER_PRICE + "," +
                    DatabaseManager.STOCK_BARCODE + "," +
                    DatabaseManager.STOCK_SPELL +
                    " FROM " + DatabaseManager.STOCK_TABLE_NAME + " WHERE  " + DatabaseManager.STOCK_TYPEID + "  = '" + typeId + "'" + " ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;//查询表名为“stock”的所有内容
            cursor = mDataBase.rawQuery(sql, null);
//			cursor = mDataBase.query( DatabaseManager.STOCK_TABLE_NAME, new String[]{
//							DatabaseManager.STOCK_STOCKID,
//							DatabaseManager.STOCK_STOCKNAME,
//							DatabaseManager.STOCK_SPELL,
//							DatabaseManager.STOCK_TYPEID,
//							DatabaseManager.STOCK_COST,
//							DatabaseManager.STOCK_RETAIL_PRICE,
//							DatabaseManager.STOCK_MEMBER_PRICE,
//							DatabaseManager.STOCK_BARCODE
//			},  DatabaseManager.STOCK_TYPEID + "  = '" + typeId + "'",null,
//					null, null, null, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getAll(int startIndex, int pageSize, int sortMode) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sortName = DatabaseManager.STOCK_STOCKID;
                String sortUpOrDown0 = " ASC ";
                String sortUpOrDown1 = " DESC ";
                switch (sortMode){
                    case 0:
                        sortName =  DatabaseManager.STOCK_SPELL ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 1:
                        sortName =  DatabaseManager.STOCK_SPELL ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                    case 2:
                        sortName =  DatabaseManager.STOCK_STOCKID ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 3:
                        sortName =  DatabaseManager.STOCK_STOCKID ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                    case 4:
                        sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 5:
                        sortName =  DatabaseManager.STOCK_RETAIL_PRICE ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                }

                String sql = "SELECT " + DatabaseManager.STOCK_STOCKID + "," +
                        DatabaseManager.STOCK_STOCKNAME + "," +
                        DatabaseManager.STOCK_TYPEID + "," +
                        DatabaseManager.STOCK_COST + "," +
                        DatabaseManager.STOCK_RETAIL_PRICE + "," +
                        DatabaseManager.STOCK_MEMBER_PRICE + "," +
                        DatabaseManager.STOCK_BARCODE + "," +
                        DatabaseManager.STOCK_SPELL +
                        " FROM " + DatabaseManager.STOCK_TABLE_NAME + " ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;//查询表名为“stock”的所有内容
                cursor = mDataBase.rawQuery(sql, null);
//			cursor = mDataBase.query(DatabaseManager.STOCK_TABLE_NAME, new String[]{
//					DatabaseManager.STOCK_STOCKID,
//					DatabaseManager.STOCK_STOCKNAME,
//					DatabaseManager.STOCK_SPELL,
//					DatabaseManager.STOCK_TYPEID,
//					DatabaseManager.STOCK_COST,
//					DatabaseManager.STOCK_RETAIL_PRICE,
//					DatabaseManager.STOCK_MEMBER_PRICE,
//					DatabaseManager.STOCK_BARCODE
//			}, null, null, null, null, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public int deleteStock(String stockid) {
        int row = -1;
            try {
                mDataBase.delete(DatabaseManager.STOCK_TABLE_NAME, DatabaseManager.STOCK_STOCKID + " = '" + stockid +"'", null);
                row = 1;
            } catch (Exception e) {
                e.printStackTrace();
            }
        return row;
    }

    public void deleteAllStocks() {
        mDataBase.delete(DatabaseManager.STOCK_TABLE_NAME, null, null);
    }

    /**
     * 添加商品类目
     */
    public int insertStockType(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.STOCK_TYPE_TABLE_NAME
                            + "(" + DatabaseManager.STOCK_TYPE_TYPEID + ","
                            + DatabaseManager.STOCK_TYPE_TYPENAME + ") VALUES (?,?)",
                    new Object[]{values.get(DatabaseManager.STOCK_TYPE_TYPEID),
                            values.get(DatabaseManager.STOCK_TYPE_TYPENAME)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getAllStockType() {
        Cursor cursor = null;
        if (mDataBase != null) {
            cursor = mDataBase.query(DatabaseManager.STOCK_TYPE_TABLE_NAME, new String[]{
                    DatabaseManager.STOCK_TYPE_TYPEID,
                    DatabaseManager.STOCK_TYPE_TYPENAME
            }, null, null, null, null, null);
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public void deleteAllStockType() {
        mDataBase.delete(DatabaseManager.STOCK_TYPE_TABLE_NAME, null, null);
    }

    /**
     * 添加会员
     */
    public int insertMember(ContentValues values) {
        int row = -1;
        try {
            String nameStr = (String)values.get(DatabaseManager.MEMBER_NAME);
            String str = "#";
            if (nameStr.length() != 0)
                str = Utils.cn2FirstSpell(nameStr).substring(0, 1);
            if (str.matches("[A-Z]")) {

            } else {
                str = "#";
            }

            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.MEMBER_TABLE_NAME
                            + "(" + DatabaseManager.MEMBER_MEMBERID + "," +
                            DatabaseManager.MEMBER_NAME + "," +
                            DatabaseManager.MEMBER_NAME_SPELL + "," +
                            DatabaseManager.MEMBER_SEX + "," +
                            DatabaseManager.MEMBER_MOBILE + "," +
                            DatabaseManager.MEMBER_POINT + "," +
                            DatabaseManager.MEMBER_MEMBERTYPE + "," +
                            DatabaseManager.MEMBER_CARDID + "," +
                            DatabaseManager.MEMBER_MODIFY_SN + "," +
                            DatabaseManager.MEMBER_TOTAL_CONSUME + ") VALUES (?,?,?,?,?,?,?,?,?,?)",
                    new Object[]{values.get(DatabaseManager.MEMBER_MEMBERID),
                            values.get(DatabaseManager.MEMBER_NAME),
                            str,
                            values.get(DatabaseManager.MEMBER_SEX),
                            values.get(DatabaseManager.MEMBER_MOBILE),
                            values.get(DatabaseManager.MEMBER_POINT),
                            values.get(DatabaseManager.MEMBER_MEMBERTYPE),
                            values.get(DatabaseManager.MEMBER_CARDID),
                            values.get(DatabaseManager.MEMBER_MODIFY_SN),
                            values.get(DatabaseManager.MEMBER_TOTAL_CONSUME)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getByMemberId(String memberId, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.MEMBER_NAME_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.MEMBER_POINT ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.MEMBER_POINT ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.MEMBER_TOTAL_CONSUME ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.MEMBER_TOTAL_CONSUME ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }
            cursor = mDataBase.query(DatabaseManager.MEMBER_TABLE_NAME, new String[]{
                            DatabaseManager.MEMBER_MEMBERID,
                            DatabaseManager.MEMBER_NAME,
                            DatabaseManager.MEMBER_NAME_SPELL,
                            DatabaseManager.MEMBER_SEX,
                            DatabaseManager.MEMBER_MOBILE,
                            DatabaseManager.MEMBER_POINT,
                            DatabaseManager.MEMBER_MEMBERTYPE,
                            DatabaseManager.MEMBER_CARDID,
                            DatabaseManager.MEMBER_MODIFY_SN,
                            DatabaseManager.MEMBER_TOTAL_CONSUME
                    }, DatabaseManager.MEMBER_MEMBERID + "  like '%" + memberId + "%'", null,
                    null, null, sortName + sortUpOrDown0, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getByMemberName(String name, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.MEMBER_NAME_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.MEMBER_POINT ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.MEMBER_POINT ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.MEMBER_TOTAL_CONSUME ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.MEMBER_TOTAL_CONSUME ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }
            cursor = mDataBase.query(DatabaseManager.MEMBER_TABLE_NAME, new String[]{
                            DatabaseManager.MEMBER_MEMBERID,
                            DatabaseManager.MEMBER_NAME,
                            DatabaseManager.MEMBER_NAME_SPELL,
                            DatabaseManager.MEMBER_SEX,
                            DatabaseManager.MEMBER_MOBILE,
                            DatabaseManager.MEMBER_POINT,
                            DatabaseManager.MEMBER_MEMBERTYPE,
                            DatabaseManager.MEMBER_CARDID,
                            DatabaseManager.MEMBER_MODIFY_SN,
                            DatabaseManager.MEMBER_TOTAL_CONSUME
                    }, DatabaseManager.MEMBER_NAME + "  like '%" + name + "%'", null,
                    null, null, sortName + sortUpOrDown0, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getByMemberMobile(String mobile, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.MEMBER_NAME_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.MEMBER_POINT ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.MEMBER_POINT ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.MEMBER_TOTAL_CONSUME ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.MEMBER_TOTAL_CONSUME ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }
            cursor = mDataBase.query(DatabaseManager.MEMBER_TABLE_NAME, new String[]{
                            DatabaseManager.MEMBER_MEMBERID,
                            DatabaseManager.MEMBER_NAME,
                            DatabaseManager.MEMBER_NAME_SPELL,
                            DatabaseManager.MEMBER_SEX,
                            DatabaseManager.MEMBER_MOBILE,
                            DatabaseManager.MEMBER_POINT,
                            DatabaseManager.MEMBER_MEMBERTYPE,
                            DatabaseManager.MEMBER_CARDID,
                            DatabaseManager.MEMBER_MODIFY_SN,
                            DatabaseManager.MEMBER_TOTAL_CONSUME
                    }, DatabaseManager.MEMBER_MOBILE + "  like '%" + mobile + "%'", null,
                    null, null, sortName + sortUpOrDown0, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getAllMember(int startIndex, int pageSize, String memberPointStr, int sortMode) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sortName = DatabaseManager.MEMBER_NAME_SPELL;
                String sortUpOrDown0 = " ASC ";
                String sortUpOrDown1 = " DESC ";
                switch (sortMode){
                    case 0:
                        sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 1:
                        sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                    case 2:
                        sortName =  DatabaseManager.MEMBER_POINT ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 3:
                        sortName =  DatabaseManager.MEMBER_POINT ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                    case 4:
                        sortName =  DatabaseManager.MEMBER_TOTAL_CONSUME ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 5:
                        sortName =  DatabaseManager.MEMBER_TOTAL_CONSUME ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                }
                String sql = "SELECT " + DatabaseManager.MEMBER_MEMBERID + "," +
                        DatabaseManager.MEMBER_NAME + "," +
                        DatabaseManager.MEMBER_NAME_SPELL + "," +
                        DatabaseManager.MEMBER_SEX + "," +
                        DatabaseManager.MEMBER_MOBILE + "," +
                        DatabaseManager.MEMBER_POINT + "," +
                        DatabaseManager.MEMBER_MEMBERTYPE + "," +
                        DatabaseManager.MEMBER_CARDID + "," +
                        DatabaseManager.MEMBER_MODIFY_SN + "," +
                        DatabaseManager.MEMBER_TOTAL_CONSUME +
                        " FROM " + DatabaseManager.MEMBER_TABLE_NAME + " WHERE " + DatabaseManager.MEMBER_POINT + " >= " + memberPointStr +" ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;   //sql的中文排序
                cursor = mDataBase.rawQuery(sql, null);

//                String s = startIndex + "," + pageSize;
//                cursor = mDataBase.query(DatabaseManager.MEMBER_TABLE_NAME, new String[]{
//                        DatabaseManager.MEMBER_MEMBERID,
//                        DatabaseManager.MEMBER_NAME,
//                        DatabaseManager.MEMBER_SEX,
//                        DatabaseManager.MEMBER_MOBILE,
//                        DatabaseManager.MEMBER_POINT,
//                        DatabaseManager.MEMBER_MEMBERTYPE,
//                        DatabaseManager.MEMBER_CARDID,
//                        DatabaseManager.MEMBER_MODIFY_SN,
//                        DatabaseManager.MEMBER_TOTAL_CONSUME
//                }, null, null, null, null, "name limit " + s);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public int deleteMember(String memberid) {
        int row = -1;
        try {
            mDataBase.delete(DatabaseManager.MEMBER_TABLE_NAME, DatabaseManager.MEMBER_MEMBERID + " = '" + memberid +"'", null);
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return row;
    }

    public void deleteAllMember() {
        mDataBase.delete(DatabaseManager.MEMBER_TABLE_NAME, null, null);
    }

    /**
     * 插入销售额表
     */
    public int insertPayMaster(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.PAY_MASTER_TABLE_NAME
                            + "(" + DatabaseManager.PAY_MASTER_BILLNO + ","
                            + DatabaseManager.PAY_MASTER_OPERDATE + ","
                            + DatabaseManager.PAY_MASTER_BLOTOUT + ","
                            + DatabaseManager.PAY_MASTER_TOTAL + ","
                            + DatabaseManager.PAY_MASTER_RECEIVABLE  + ") VALUES (?,?,?,?,?)",
                    new Object[]{values.get(DatabaseManager.PAY_MASTER_BILLNO),
                            values.get(DatabaseManager.PAY_MASTER_OPERDATE),
                            values.get(DatabaseManager.PAY_MASTER_BLOTOUT),
                            values.get(DatabaseManager.PAY_MASTER_TOTAL),
                            values.get(DatabaseManager.PAY_MASTER_RECEIVABLE)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getByPayMasterOperdate(String date) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "SELECT " + DatabaseManager.PAY_MASTER_BILLNO + "," +
                        DatabaseManager.PAY_MASTER_OPERDATE + "," +
                        DatabaseManager.PAY_MASTER_BLOTOUT + "," +
                        DatabaseManager.PAY_MASTER_TOTAL + "," +
                        DatabaseManager.PAY_MASTER_RECEIVABLE +
                        " FROM " + DatabaseManager.PAY_MASTER_TABLE_NAME + " WHERE " + DatabaseManager.PAY_MASTER_OPERDATE + "  > '" + date + " 00:00:00' and " + DatabaseManager.PAY_MASTER_OPERDATE + "<'" + date + " 23:59:59'";
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    /**
     * 插入销售详情表
     */
    public int insertSaleDetail(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.SALE_DETAIL_TABLE_NAME
                            + "(" + DatabaseManager.SALE_DETAIL_BILLNO + ","
                            + DatabaseManager.SALE_DETAIL_STOCKID + ","
                            + DatabaseManager.SALE_DETAIL_QUANTITY + ","
                            + DatabaseManager.SALE_DETAIL_OPERATEDATE + ","
                            + DatabaseManager.SALE_DETAIL_PRICE + ","
                            + DatabaseManager.SALE_DETAIL_COST + ","
                            + DatabaseManager.SALE_DETAIL_PRICE_ORIG  + ") VALUES (?,?,?,?,?,?,?)",
                    new Object[]{values.get(DatabaseManager.SALE_DETAIL_BILLNO),
                            values.get(DatabaseManager.SALE_DETAIL_STOCKID),
                            values.get(DatabaseManager.SALE_DETAIL_QUANTITY),
                            values.get(DatabaseManager.SALE_DETAIL_OPERATEDATE),
                            values.get(DatabaseManager.SALE_DETAIL_PRICE),
                            values.get(DatabaseManager.SALE_DETAIL_COST),
                            values.get(DatabaseManager.SALE_DETAIL_PRICE_ORIG)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getSaleDetailByDate(String date) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "SELECT " + DatabaseManager.SALE_DETAIL_BILLNO + "," +
                        DatabaseManager.SALE_DETAIL_STOCKID + "," +
                        DatabaseManager.SALE_DETAIL_QUANTITY + "," +
                        DatabaseManager.SALE_DETAIL_OPERATEDATE + "," +
                        DatabaseManager.SALE_DETAIL_PRICE + "," +
                        DatabaseManager.SALE_DETAIL_COST + "," +
                        DatabaseManager.SALE_DETAIL_PRICE_ORIG +
                        " FROM " + DatabaseManager.SALE_DETAIL_TABLE_NAME + " WHERE " + DatabaseManager.SALE_DETAIL_OPERATEDATE + "  > '" + date + " 00:00:00' and " + DatabaseManager.PAY_MASTER_OPERDATE + "<'" + date + " 23:59:59'";
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public Cursor getSaleDetailByStockid(String stockid) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "SELECT " + DatabaseManager.SALE_DETAIL_BILLNO + "," +
                        DatabaseManager.SALE_DETAIL_STOCKID + "," +
                        DatabaseManager.SALE_DETAIL_QUANTITY + "," +
                        DatabaseManager.SALE_DETAIL_OPERATEDATE + "," +
                        DatabaseManager.SALE_DETAIL_PRICE + "," +
                        DatabaseManager.SALE_DETAIL_COST + "," +
                        DatabaseManager.SALE_DETAIL_PRICE_ORIG +
                        " FROM " + DatabaseManager.SALE_DETAIL_TABLE_NAME + " WHERE " + DatabaseManager.SALE_DETAIL_STOCKID + "  = " + stockid;
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public Cursor getSaleDetailByBillno(String billno) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "SELECT " + DatabaseManager.SALE_DETAIL_BILLNO + "," +
                        DatabaseManager.SALE_DETAIL_STOCKID + "," +
                        DatabaseManager.SALE_DETAIL_QUANTITY + "," +
                        DatabaseManager.SALE_DETAIL_OPERATEDATE + "," +
                        DatabaseManager.SALE_DETAIL_PRICE + "," +
                        DatabaseManager.SALE_DETAIL_COST + "," +
                        DatabaseManager.SALE_DETAIL_PRICE_ORIG +
                        " FROM " + DatabaseManager.SALE_DETAIL_TABLE_NAME + " WHERE " + DatabaseManager.SALE_DETAIL_BILLNO + "  = '" + billno + "'";
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }





    /**
     * 添加商品类目
     */
    public int insertIsszmbalv3StockType(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.ISSZMBALV3_ITEM_CLS_TABLE_NAME
                            + "(" + DatabaseManager.ISSZMBALV3_ITEM_CLS_ITEM_CLSNO + ","
                            + DatabaseManager.ISSZMBALV3_ITEM_CLS_ITEM_CLSNAME + ") VALUES (?,?)",
                    new Object[]{values.get(DatabaseManager.ISSZMBALV3_ITEM_CLS_ITEM_CLSNO),
                            values.get(DatabaseManager.ISSZMBALV3_ITEM_CLS_ITEM_CLSNAME)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getAllIsszmbalv3StockType() {
        Cursor cursor = null;
        if (mDataBase != null) {
            cursor = mDataBase.query(DatabaseManager.ISSZMBALV3_ITEM_CLS_TABLE_NAME, new String[]{
                    DatabaseManager.ISSZMBALV3_ITEM_CLS_ITEM_CLSNO,
                    DatabaseManager.ISSZMBALV3_ITEM_CLS_ITEM_CLSNAME
            }, null, null, null, null, null);
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public void deleteAllIsszmbalv3StockType() {
        mDataBase.delete(DatabaseManager.ISSZMBALV3_ITEM_CLS_TABLE_NAME, null, null);
    }

    /**
     * 添加商品
     */
    public int insertIsszmbalv3Stock(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME
                            + "(" + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_subname + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_item_rem + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_price + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_sale_price + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_measure_flag + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_new_oper_id + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_modify_oper_id + ","
                            + DatabaseManager.ISSZMBALV3_t_bd_item_vip_acc_flag + ") VALUES (?,?,?,?,?,?,?,?,?,?,?)",
                    new Object[]{values.get(DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_info_item_subname),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_item_rem),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_price),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_sale_price),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_measure_flag),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_new_oper_id),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_modify_oper_id),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_item_vip_acc_flag)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getAllIsszmbalv3Stock(int startIndex, int pageSize, int sortMode) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sortName = DatabaseManager.ISSZMBALV3_t_bd_item_item_rem;
                String sortUpOrDown0 = " ASC ";
                String sortUpOrDown1 = " DESC ";
                switch (sortMode){
                    case 0:
                        sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 1:
                        sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                    case 2:
                        sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 3:
                        sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                    case 4:
                        sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 5:
                        sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                }

                String sql = "SELECT " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_info_item_subname + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_item_rem + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_price + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_sale_price + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_measure_flag + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_new_oper_id + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_modify_oper_id + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_item_vip_acc_flag +
                        " FROM " + DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME + " ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public Cursor getIsszmbalv3StockByTypeId(String typeId, int startIndex, int pageSize, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.ISSZMBALV3_t_bd_item_item_rem;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }

            String sql = "SELECT " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_subname + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_item_rem + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_sale_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_measure_flag + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_new_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_modify_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_vip_acc_flag +
                    " FROM " + DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME + " WHERE  " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno + "  = '" + typeId + "'" + " ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;
            cursor = mDataBase.rawQuery(sql, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getIsszmbalv3StockByNo(String stockno, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.ISSZMBALV3_t_bd_item_item_rem;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }

            String sql = "SELECT " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_subname + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_item_rem + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_sale_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_measure_flag + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_new_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_modify_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_vip_acc_flag +
                    " FROM " + DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME + " WHERE  " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + "  like '%" + stockno + "%'" + " ORDER BY " + sortName + sortUpOrDown0  ;
            cursor = mDataBase.rawQuery(sql, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getIsszmbalv3StockByName(String stockname, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.ISSZMBALV3_t_bd_item_item_rem;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }
            String sql = "SELECT " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_subname + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_item_rem + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_sale_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_measure_flag + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_new_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_modify_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_vip_acc_flag +
                    " FROM " + DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME + " WHERE  " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name + "  like '%" + stockname + "%'" + " ORDER BY " + sortName + sortUpOrDown0 ;
            cursor = mDataBase.rawQuery(sql, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getIsszmbalv3StockBySpell(String stockspell, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.ISSZMBALV3_t_bd_item_item_rem;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_item_rem ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.ISSZMBALV3_t_bd_item_sale_price ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }
            String sql = "SELECT " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_subname + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_item_rem + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_sale_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_measure_flag + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_new_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_modify_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_vip_acc_flag +
                    " FROM " + DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME + " WHERE  " + DatabaseManager.ISSZMBALV3_t_bd_item_item_rem + "  like '%" + stockspell + "%'" + " ORDER BY " + sortName + sortUpOrDown0 ;
            cursor = mDataBase.rawQuery(sql, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getIsszmbalv3StockByNo1(String stockno) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sql = "SELECT " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_subname + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_info_item_clsno + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_item_rem + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_sale_price + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_measure_flag + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_new_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_modify_oper_id + "," +
                    DatabaseManager.ISSZMBALV3_t_bd_item_vip_acc_flag +
                    " FROM " + DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME + " WHERE  " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + "  = '" + stockno + "' ORDER BY " + DatabaseManager.ISSZMBALV3_t_bd_item_info_item_name ;
            cursor = mDataBase.rawQuery(sql, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public int deleteIsszmbalv3Stock(String stockno) {
        int row = -1;
        try {
            mDataBase.delete(DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME, DatabaseManager.ISSZMBALV3_t_bd_item_info_item_no + " = '" + stockno +"'", null);
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return row;
    }

    public void deleteAllIsszmbalv3Stocks() {
        mDataBase.delete(DatabaseManager.ISSZMBALV3_t_bd_item_info_TABLE_NAME, null, null);
    }

    /**
     * 添加会员
     */
    public int insertIsszmbalv3Member(ContentValues values) {
        int row = -1;
        try {
            String nameStr = (String)values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_vip_name);
            String str = "#";
            if (nameStr.length() != 0)
                str = Utils.cn2FirstSpell(nameStr).substring(0, 1);
            if (str.matches("[A-Z]")) {

            } else {
                str = "#";
            }

            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.ISSZMBALV3_t_rm_vip_info_TABLE_NAME
                            + "(" + DatabaseManager.ISSZMBALV3_t_rm_vip_card_type + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_id + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_no + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_name + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_sex + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_tel + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_email + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_mobile + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_consum_count + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_dec_num + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_start_date + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_end_date + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_sav_start_date + "," +
                            DatabaseManager.ISSZMBALV3_t_rm_vip_sav_end_date + "," +
                            DatabaseManager.MEMBER_NAME_SPELL + ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                    new Object[]{values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_card_type),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_card_id),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_card_no),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_vip_name),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_vip_sex),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_vip_tel),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_vip_email),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_mobile),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_consum_count),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_dec_num),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_vip_start_date),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_vip_end_date),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_sav_start_date),
                            values.get(DatabaseManager.ISSZMBALV3_t_rm_vip_sav_end_date),
                            str});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getByIsszmbalv3MemberCardNo(String memberCardNo, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.MEMBER_NAME_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }
            cursor = mDataBase.query(DatabaseManager.ISSZMBALV3_t_rm_vip_info_TABLE_NAME, new String[]{
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_type,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_id,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_no,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_name,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_sex,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_tel,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_email,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_mobile,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_consum_count,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_dec_num,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_start_date,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_end_date,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_sav_start_date,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_sav_end_date,
                            DatabaseManager.MEMBER_NAME_SPELL
                    }, DatabaseManager.ISSZMBALV3_t_rm_vip_card_no + "  like '%" + memberCardNo + "%'" , null,
                    null, null, sortName + sortUpOrDown0, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getByIsszmbalv3MemberName(String name, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.MEMBER_NAME_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }
            cursor = mDataBase.query(DatabaseManager.ISSZMBALV3_t_rm_vip_info_TABLE_NAME, new String[]{
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_type,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_id,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_no,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_name,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_sex,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_tel,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_email,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_mobile,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_consum_count,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_dec_num,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_start_date,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_end_date,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_sav_start_date,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_sav_end_date,
                            DatabaseManager.MEMBER_NAME_SPELL
                    }, DatabaseManager.ISSZMBALV3_t_rm_vip_vip_name + "  like '%" + name + "%'", null,
                    null, null, sortName + sortUpOrDown0, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getByIsszmbalv3MemberMobile(String mobile, int sortMode) throws SQLException {
        Cursor cursor = null;
        if (mDataBase != null) {
            String sortName = DatabaseManager.MEMBER_NAME_SPELL;
            String sortUpOrDown0 = " ASC ";
            String sortUpOrDown1 = " DESC ";
            switch (sortMode){
                case 0:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 1:
                    sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 2:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 3:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
                case 4:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt ;
                    sortUpOrDown0 = " ASC ";
                    sortUpOrDown1 = " DESC ";
                    break;
                case 5:
                    sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt ;
                    sortUpOrDown0 = " DESC ";
                    sortUpOrDown1 = " ASC ";
                    break;
            }
            cursor = mDataBase.query(DatabaseManager.ISSZMBALV3_t_rm_vip_info_TABLE_NAME, new String[]{
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_type,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_id,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_card_no,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_name,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_sex,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_tel,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_email,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_mobile,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_consum_count,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_dec_num,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_start_date,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_vip_end_date,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_sav_start_date,
                            DatabaseManager.ISSZMBALV3_t_rm_vip_sav_end_date,
                            DatabaseManager.MEMBER_NAME_SPELL
                    }, DatabaseManager.ISSZMBALV3_t_rm_vip_mobile + "  like '%" + mobile + "%' or " + DatabaseManager.ISSZMBALV3_t_rm_vip_vip_tel + "  like '%" + mobile + "%'", null,
                    null, null, sortName + sortUpOrDown0, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }

    public Cursor getAllIsszmbalv3Member(int startIndex, int pageSize, String memberPointStr, int sortMode) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sortName = DatabaseManager.MEMBER_NAME_SPELL;
                String sortUpOrDown0 = " ASC ";
                String sortUpOrDown1 = " DESC ";
                switch (sortMode){
                    case 0:
                        sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 1:
                        sortName =  DatabaseManager.MEMBER_NAME_SPELL ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                    case 2:
                        sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 3:
                        sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                    case 4:
                        sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt ;
                        sortUpOrDown0 = " ASC ";
                        sortUpOrDown1 = " DESC ";
                        break;
                    case 5:
                        sortName =  DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt ;
                        sortUpOrDown0 = " DESC ";
                        sortUpOrDown1 = " ASC ";
                        break;
                }

                String sql = "SELECT " + DatabaseManager.ISSZMBALV3_t_rm_vip_card_type + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_card_id + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_card_no + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_vip_name + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_vip_sex + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_vip_tel + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_vip_email + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_mobile + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_consum_count + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_consum_amt + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_dec_num + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_vip_start_date + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_vip_end_date + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_sav_start_date + "," +
                        DatabaseManager.ISSZMBALV3_t_rm_vip_sav_end_date + "," +
                        DatabaseManager.MEMBER_NAME_SPELL +
                        " FROM " + DatabaseManager.ISSZMBALV3_t_rm_vip_info_TABLE_NAME + " WHERE " + DatabaseManager.ISSZMBALV3_t_rm_vip_acc_num + " >= " + memberPointStr +" ORDER BY " + sortName + sortUpOrDown0 + " LIMIT " + startIndex + "," + pageSize;   //sql的中文排序
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public int deleteIsszmbalv3Member(String memberCardid) {
        int row = -1;
        try {
            mDataBase.delete(DatabaseManager.ISSZMBALV3_t_rm_vip_info_TABLE_NAME, DatabaseManager.ISSZMBALV3_t_rm_vip_card_id + " = '" + memberCardid +"'", null);
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return row;
    }

    public void deleteAllIsszmbalv3Member() {
        mDataBase.delete(DatabaseManager.ISSZMBALV3_t_rm_vip_info_TABLE_NAME, null, null);
    }

    /**
     * 插入门店信息
     */
    public int insertIsszmbalv3BranchInfo(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.ISSZMBALV3_BRANCH_INFO_TABLE_NAME
                            + "(" + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + "," +
                            DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NAME + "," +
                            DatabaseManager.ISSZMBALV3_BRANCH_INFO_PROPERTY +  ") VALUES (?,?,?)",
                    new Object[]{values.get(DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO),
                            values.get(DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NAME),
                            values.get(DatabaseManager.ISSZMBALV3_BRANCH_INFO_PROPERTY)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getIsszmbalv3BranchInfo() {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "SELECT " + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + "," +
                            DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NAME + "," +
                            DatabaseManager.ISSZMBALV3_BRANCH_INFO_PROPERTY +
                            " FROM " + DatabaseManager.ISSZMBALV3_BRANCH_INFO_TABLE_NAME;
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public void deleteAllIsszmbalv3Branch() {
        mDataBase.delete(DatabaseManager.ISSZMBALV3_BRANCH_INFO_TABLE_NAME, null, null);
    }

    /**
     * 插入门店信息
     */
    public int insertIsszmbalv3SupcustInfo(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.ISSZMBALV3_t_bd_supcust_info_TABLE_NAME
                            + "(" + DatabaseManager.ISSZMBALV3_t_bd_supcust_info_supcust_no + "," +
                            DatabaseManager.ISSZMBALV3_t_bd_supcust_info_sup_name + "," +
                            DatabaseManager.ISSZMBALV3_t_bd_supcust_info_sup_type +  ") VALUES (?,?,?)",
                    new Object[]{values.get(DatabaseManager.ISSZMBALV3_t_bd_supcust_info_supcust_no),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_supcust_info_sup_name),
                            values.get(DatabaseManager.ISSZMBALV3_t_bd_supcust_info_sup_type)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getIsszmbalv3SupcustInfo() {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "SELECT " + DatabaseManager.ISSZMBALV3_t_bd_supcust_info_supcust_no + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_supcust_info_sup_name + "," +
                        DatabaseManager.ISSZMBALV3_t_bd_supcust_info_sup_type +
                        " FROM " + DatabaseManager.ISSZMBALV3_t_bd_supcust_info_TABLE_NAME;
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    /**
     * 删除供应商信息
     */
    public void deleteAllIsszmbalv3Supcust() {
        mDataBase.delete(DatabaseManager.ISSZMBALV3_t_bd_supcust_info_TABLE_NAME, null, null);
    }

    /**
     * 插入销售额表
     */
    public int insertIsszmbalv3PayFlow(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.ISSZMBALV3_PAY_FLOW_TABLE_NAME
                            + "(" + DatabaseManager.ISSZMBALV3_PAY_FLOW_FLOW_NO + ","
                            + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + ","
                            + DatabaseManager.ISSZMBALV3_PAY_FLOW_OPERDATE + ","
                            + DatabaseManager.ISSZMBALV3_PAY_FLOW_SALE_AMOUNT + ","
                            + DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_AMOUNT  + ","
                            + DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_WAY  + ") VALUES (?,?,?,?,?,?)",
                    new Object[]{values.get(DatabaseManager.ISSZMBALV3_PAY_FLOW_FLOW_NO),
                            values.get(DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO),
                            values.get(DatabaseManager.ISSZMBALV3_PAY_FLOW_OPERDATE),
                            values.get(DatabaseManager.ISSZMBALV3_PAY_FLOW_SALE_AMOUNT),
                            values.get(DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_AMOUNT),
                            values.get(DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_WAY)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getIsszmbalv3PayFlowByOperdate(String date, String branchNo) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "";
                if( !TextUtils.isEmpty(branchNo)){
                    sql = "SELECT " + DatabaseManager.ISSZMBALV3_PAY_FLOW_FLOW_NO + "," +
                            DatabaseManager.ISSZMBALV3_PAY_FLOW_OPERDATE + "," +
                            DatabaseManager.ISSZMBALV3_PAY_FLOW_SALE_AMOUNT + "," +
                            DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_AMOUNT + "," +
                            DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_WAY +
                            " FROM " + DatabaseManager.ISSZMBALV3_PAY_FLOW_TABLE_NAME + " WHERE " + DatabaseManager.ISSZMBALV3_PAY_FLOW_OPERDATE + "  > '" + date + " 00:00:00' and " + DatabaseManager.ISSZMBALV3_PAY_FLOW_OPERDATE + "<'" + date + " 23:59:59'  and " + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + "=" + branchNo;
                }else{
                    sql = "SELECT " + DatabaseManager.ISSZMBALV3_PAY_FLOW_FLOW_NO + "," +
                            DatabaseManager.ISSZMBALV3_PAY_FLOW_OPERDATE + "," +
                            DatabaseManager.ISSZMBALV3_PAY_FLOW_SALE_AMOUNT + "," +
                            DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_AMOUNT + "," +
                            DatabaseManager.ISSZMBALV3_PAY_FLOW_PAY_WAY +
                            " FROM " + DatabaseManager.ISSZMBALV3_PAY_FLOW_TABLE_NAME + " WHERE " + DatabaseManager.ISSZMBALV3_PAY_FLOW_OPERDATE + "  > '" + date + " 00:00:00' and " + DatabaseManager.ISSZMBALV3_PAY_FLOW_OPERDATE + "<'" + date + " 23:59:59'";
                }
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public void deleteAllIsszmbalv3PayFlow() {
        mDataBase.delete(DatabaseManager.ISSZMBALV3_PAY_FLOW_TABLE_NAME, null, null);
    }

    /**
     * 插入销售详情表
     */
    public int insertIsszmbalv3SaleDetail(ContentValues values) {
        int row = -1;
        try {
            mDataBase.execSQL(
                    "INSERT INTO "
                            + DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME
                            + "(" + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + ","
                            + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + ","
                            + DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + ","
                            + DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + ","
                            + DatabaseManager.ISSZMBALV3_SALE_FLOW_SOURCE_PRICE + ","
                            + DatabaseManager.ISSZMBALV3_SALE_FLOW_COST_PRICE + ","
                            + DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_QNTY + ","
                            + DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_MONER  + ") VALUES (?,?,?,?,?,?,?,?)",
                    new Object[]{values.get(DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO),
                            values.get(DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO),
                            values.get(DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE),
                            values.get(DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO),
                            values.get(DatabaseManager.ISSZMBALV3_SALE_FLOW_SOURCE_PRICE),
                            values.get(DatabaseManager.ISSZMBALV3_SALE_FLOW_COST_PRICE),
                            values.get(DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_QNTY),
                            values.get(DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_MONER)});
            row = 1;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return row;
    }

    public Cursor getIsszmbalv3SaleDetailByDate(String date, String branchNo) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "";
                if( !TextUtils.isEmpty(branchNo)) {
                    sql = "SELECT " + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SOURCE_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_COST_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_QNTY + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_MONER +
                            " FROM " + DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME + " WHERE " + DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "  > '" + date + " 00:00:00' and " + DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "<'" + date + " 23:59:59'  and " + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + "=" + branchNo;
                }else{
                    sql = "SELECT " + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SOURCE_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_COST_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_QNTY + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_MONER +
                            " FROM " + DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME + " WHERE " + DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "  > '" + date + " 00:00:00' and " + DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "<'" + date + " 23:59:59'";
                }
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public Cursor getIsszmbalv3SaleDetailByStockno(String stockno, String branchNo) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "";
                if( !TextUtils.isEmpty(branchNo)) {
                    sql = "SELECT " + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SOURCE_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_COST_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_QNTY + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_MONER +
                            " FROM " + DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME + " WHERE " + DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + "  = '" + stockno + "'   and " + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + "=" + branchNo;
                }else{
                    sql = "SELECT " + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SOURCE_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_COST_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_QNTY + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_MONER +
                            " FROM " + DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME + " WHERE " + DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + "  = '" + stockno + "'";
                }
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public Cursor getIsszmbalv3SaleDetailByFlowno(String flowno , String branchNo) {
        Cursor cursor = null;
        if (mDataBase != null) {
            try {
                String sql = "";
                if( !TextUtils.isEmpty(branchNo)){
                    sql = "SELECT " + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SOURCE_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_COST_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_QNTY + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_MONER +
                            " FROM " + DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME + " WHERE " + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + "  = '" + flowno + "'  and " + DatabaseManager.ISSZMBALV3_BRANCH_INFO_BRANCH_NO + "=" + branchNo;
                }else{
                    sql = "SELECT " + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_OPERDATE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_ITEM_NO + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SOURCE_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_COST_PRICE + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_QNTY + "," +
                            DatabaseManager.ISSZMBALV3_SALE_FLOW_SALE_MONER +
                            " FROM " + DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME + " WHERE " + DatabaseManager.ISSZMBALV3_SALE_FLOW_FLOW_NO + "  = '" + flowno + "'";
                }
                cursor = mDataBase.rawQuery(sql, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public void deleteAllIsszmbalv3SaleDetail() {
        mDataBase.delete(DatabaseManager.ISSZMBALV3_SALE_FLOW_TABLE_NAME, null, null);
    }
}
